<template>
  <div v-if="visible" class="dialog">
    <div class="dialog-content">
      <div class="dialog-header">
        <span class="dialog-title">转诊审核</span>
        <button class="dialog-close-btn" @click="closeDialog">×</button>
      </div>
      <div class="dialog-body">
        <div class="form-item">
          <label class="label">审批意见</label>
          <radio-group v-model="approval">
            <label class="radio-label"> <radio value="Accepted" /> 通过 </label>
            <label class="radio-label"> <radio value="Rejected" /> 拒绝 </label>
          </radio-group>
        </div>
        <div class="form-item">
          <label class="label">转诊类型</label>
          <div class="btn-group">
            <button
              :class="{ active: transferType === 'Routine Referral' }"
              @click="setTransferType('Routine Referral')"
            >
              转门诊
            </button>
            <button
              :class="{ active: transferType === 'Emergency Referral' }"
              @click="setTransferType('Emergency Referral')"
            >
              转急诊
            </button>
            <button
              :class="{ active: transferType === 'Inpatient Referral' }"
              @click="setTransferType('Inpatient Referral')"
            >
              转住院
            </button>
          </div>
        </div>
        <div class="form-item">
          <label class="label">接收科室</label>
          <input class="input" placeholder="请输入" v-model="department" />
        </div>
        <div class="form-item">
          <label class="label">接收病区</label>
          <input class="input" placeholder="请输入" v-model="target_ward" />
        </div>
        <div class="form-item">
          <label class="label">审批医生</label>
          <input class="input" placeholder="请输入" v-model="doctor" />
        </div>
        <div class="form-item">
          <label class="label">建议入院时间</label>
          <input
            class="input"
            placeholder="请选择日期"
            v-model="admissionTime"
          />
        </div>
      </div>
      <div class="dialog-footer">
        <button class="reset-btn" @click="resetForm">重置</button>
        <button class="confirm-btn" @click="confirmApproval">确认</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      target_ward_text: "接收病区",
      visible: false,
      approval: "Accepted",
      transferType: "Inpatient Referral",
      department: "",
      target_ward: "",
      doctor: "",
      admissionTime: "",
    };
  },
  methods: {
	  // api/referral/verify
    setTransferType(type) {
      this.transferType = type;
      if (this.transferType == "Routine Referral") {
        this.target_ward_text = "亚专科";
      } else {
        this.target_ward_text = "接收病区";
      }
    },
    resetForm() {
      this.approval = "Accepted";
      this.transferType = "Routine Referral";
      this.department = "";
      this.target_ward = "";
      this.doctor = "";
      this.admissionTime = "";
    },
    confirmApproval() {
      // 提交审批逻辑
      console.log({
        approval: this.approval,
        transferType: this.transferType,
        department: this.department,
        target_ward: this.target_ward,
        doctor: this.doctor,
        admissionTime: this.admissionTime,
      });
      return;
      this.closeDialog();
    },
    closeDialog() {
      this.visible = false;
    },
    showDialog() {
      this.visible = true;
    },
  },
};
</script>

<style scoped>
.dialog {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}
.dialog-content {
  width: 90%;
  max-width:700rpx;
  background-color: #fff;
  border-radius: 8px;
  overflow: hidden;
}
.dialog-header {
  padding: 16px;
  border-bottom: 1px solid #ddd;
}
.dialog-title {
  font-size:26rpx;
  font-weight: bold;
}
.dialog-close-btn {
  font-size: 24rpx;
  background: none;
  border: none;
  float: right;
  outline: none;
}
.dialog-body {
  padding: 16px;
}
.form-item {
  margin-bottom: 16px;
}
.label {
  display: block;
  margin-bottom: 8px;
  font-size: 26rpx;
}
.input {
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 26rpx;
}
.radio-label {
  margin-right: 16px;
}
.btn-group {
  display: flex;
}
.btn-group button {
	width:120rpx;
	height:80rpx;
	line-height:80rpx;
	flex: 1;
	border: 1px solid #ccc;
	background-color: #fff;
	font-size:26rpx;
}
.btn-group button.active {
  background-color: #007aff;
  color: #fff;
}
.dialog-footer {
  display: flex;
  justify-content: space-between;
  padding: 16px;
  border-top: 1px solid #ddd;
}
.reset-btn,
.confirm-btn {
  flex: 1;
  border: none;
  border-radius: 4px;
  font-size:26rpx;
  width: 120rpx;
  height: 80rpx;
  line-height: 80rpx;
}
.reset-btn {
  background-color: #f0f0f0;
  color: #333;
  margin-right: 8px;
}
.confirm-btn {
  background-color: #007aff;
  color: #fff;
}
</style>
